home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 05.zip / BS1 part 5 / SASC_6.0_Disk_7.adf / Source_And_Examples / examples / cover / covutil.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-30  |  2.5 KB  |  73 lines

  1. #include <proto/dos.h>
  2. #include <string.h>
  3.  
  4. // These are linker-defined symbols.  Always use the ADDRESS of the
  5. // symbol, not the symbol itself;  The linker will replace the reference
  6. // with the start address and length of the coverage data section
  7.  
  8. extern long __far _CoverStart;
  9. extern long __far _CoverLength;
  10.  
  11. void __stdargs _STI_cover_init(void)
  12. {
  13.     BPTR fh;
  14.     char tag[4];
  15.     long length;
  16.     
  17.     /* read in existing coverage data */
  18.     fh = Open("cover.dat", MODE_OLDFILE);
  19.     if (fh)
  20.     {
  21.        /* If the file looks OK, load the data.  The first four bytes */
  22.        /* should be 'C' 'O' 'V' '\0'; the next four, the length.     */
  23.        /* If the "COV\0" tag doesn't match up, either this isn't a   */
  24.        /* coverage file or it's an incompatible file format; either  */
  25.        /* way, give up.  If the length doesn't match, the file was   */
  26.        /* generated by a different program, so don't try to merge    */
  27.        /* the data.                                                  */
  28.        /*                                                            */
  29.        /* If the file looks good, we read it in to initialize the    */
  30.        /* coverage section.  This means that the "cover.dat" file    */
  31.        /* will reflect the results of all previous runs as well as   */
  32.        /* this run.                                                  */
  33.  
  34.        if(Read(fh, tag, 4) == 4)                   // Read the tag
  35.        {
  36.          if(memcmp(tag, "COV", 4) == 0)            // Check the tag
  37.          {
  38.             if(Read(fh, &length, 4) == 4)          // Read the length
  39.             {
  40.                if(length == (long)&_CoverLength)   // Check the length
  41.                {
  42.                   Read(fh, &_CoverStart, length);  // Read the data
  43.                }
  44.             }
  45.          }
  46.       }
  47.       Close(fh);
  48.    }
  49. }
  50.  
  51. void __stdargs _STD_cover_term(void)
  52. {
  53.    BPTR fh;
  54.    long length;
  55.     
  56.    /* Write out coverage data                            */
  57.    /* Note that we destroy the old "cover.dat" file here */
  58.    fh = Open("cover.dat", MODE_NEWFILE);
  59.    if (fh)
  60.    {
  61.       /* Note that the linker replaces &_CoverLength with the actual */
  62.       /* length; this isn't really an address.  We have to assign it */
  63.       /* to a local variable in order to take its address to pass it */
  64.       /* to Write().                                                 */
  65.       length = (long)&_CoverLength;
  66.       Write(fh, "COV", 4);             // Write the tag
  67.       Write(fh, &length, 4);           // And the length
  68.       Write(fh, &_CoverStart, length); // Dump the data
  69.       Close(fh);
  70.    }
  71. }
  72.  
  73.